package com.hbnu.system.handler;


import com.hbnu.system.config.BaseException;
import com.hbnu.system.core.base.Rest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Springboot WEB应用全局异常处理
 *
 * @author qxq
 */
@Slf4j
@ResponseBody
@RestControllerAdvice
public class BaseExceptionHandler {

    /**
     * BaseException 异常捕获处理
     *
     * @param ex 自定义BaseException异常类型
     * @return Result
     */
    @ExceptionHandler(value = {BaseException.class})
    @ResponseStatus(HttpStatus.OK)
    public Rest<?> handleException(BaseException ex) {
        log.error("BaseException 程序异常：" + ex.toString());
        return Rest.failed(ex.getMessage());
    }

}
